﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace UI.CommonForm
{
    public partial class FrmMessage : UI.ParentForm.BaseForm
    {
        private int screenWidth;//屏幕宽度     
        private int screenHeight;//屏幕高度   
        private bool finished = false;//是否完全显示提示窗口 
        private int speed = 15; //速度
        private bool isTicked = false;
        private string _title;

        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }
        private string _context;

        public string Context
        {
            get { return _context; }
            set { _context = value; }
        }

        public FrmMessage()
        {
            InitializeComponent();
        }

        public FrmMessage(string title, string context)
        {
            InitializeComponent();

            this._title = title;
            this._context = context;
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.lbTitle.Text = _title;
            this.lbContent.Text = _context;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!finished)//如果提示窗口没有完全显示    
            {
                //如果提示窗口的纵坐标与提示窗口的高度之和大于屏幕高度     
                if (Location.Y + Height >= screenHeight)
                {
                    Location = new Point(Location.X, Location.Y - speed);
                }
                else
                {
                    timer1.Enabled = false;
                    finished = true;

                    timer2.Interval = 1000 * 3;
                    timer2.Start();
                }

            }
            else//如果提示窗口已经完成了显示，并且点击了确定按钮     
            {
                //如果提示窗口没有完全从屏幕上消失     
                if (Location.Y < screenHeight)
                {
                    Location = new Point(Location.X, Location.Y + speed);
                }
                else
                { this.Close(); }
            }
        }

        private void FrmMessage_Load(object sender, EventArgs e)
        {
            screenHeight = Screen.PrimaryScreen.Bounds.Height;
            screenWidth = Screen.PrimaryScreen.Bounds.Width;
            //设置提示窗口坐标在屏幕可显示区域之外     
            Location = new Point(screenWidth - Width, screenHeight);

            timer1.Start();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (!isTicked)
            {
                isTicked = true;
                return;
            }

            this.timer2.Enabled = false;
            this.timer1.Enabled = true;
        }
    }
}
